#作业  实验8一小题
#导包
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.common.keys import Keys #特殊键盘输入导包
import random#随机数

#反爬
op = webdriver.ChromeOptions()
op.add_experimental_option('excludeSwitches', ['enable-automation'])
op.add_experimental_option('useAutomationExtension', False)
op.add_argument("--start-maximized")#窗口最大化
#打开Chrome浏览器
driver = webdriver.Chrome(options=op)
#打开网址
driver.get(r'https://www.baidu.com/')

# 随机数选择下拉列表
search=driver.find_element(By.CSS_SELECTOR, "#kw")
search.send_keys("自动化")
sleep(2)
randNumber=random.randint(1,10)#1-10个下拉列表随机选
print(randNumber)
for i in range(randNumber):
 search.send_keys(Keys.DOWN)
 sleep(1)
value1 = search.get_attribute("value")
search.send_keys(Keys.ENTER)
print(value1)
sleep(3)

assert  value1 in driver.page_source
driver.quit()
